// 医护管理-用药计划

import r from '@/utils/request';
import type { ResponseType, ListResponseType } from '../types';

enum API {
    drugPlanAdd = '/drugPlan/add', // 用药计划添加
    drugsListForPlan = '/drugs/listForPlan', // 获取老人用药计划列表
    drugPlanUpdateEndDate = '/drugPlan/updateEndDate', // 停止用药
    drugPlanGet = '/drugPlan/get', // 根据药品ID获取用药计划
}

// 获取老人存药记录数值
interface drugsListForPlanItem {
    id: number;
    drugId: number;
    time: string;
    content: string;
}

// 获取老人存药记录返回值
type drugsListForPlanRes = ListResponseType<{
    id: number;
    companyId: number;
    elderlyId: number;
    addTime: string;
    familyName: string;
    name: string;
    counts: number;
    unit: string;
    expTime: string;
    sum: number;
    norms: string;
    remarks: string;
    addAccountId: number;
    begId: number;
    begName: string;
    idCard: string;
    addAccountName: string;
    elderlyName: string;
    elderlyPhoto: string;
    elderlyGender: string;
    elderlyIdCard: string;
    houseName: string;
    buildingName: string;
    startDate: string;
    endDate: string;
    plans: drugsListForPlanItem[];
}>

// 获取老人存药记录接口
export function drugPlanListForPlanAPI(id: number): Promise<drugsListForPlanRes> {
    return r.get(API.drugsListForPlan + '/' + id)
}

export interface DrugPlanAddForm {
    drugId: number;
    startDate: string;
    plans: {
      time: string;
      content: string;
    }[]
  }

// 用药计划添加数值
interface drugPlanAddItem {
    time:    string;
    content: string;
}

// 用药计划添加参数
interface drugPlanAddParams {
    drugId:    number;
    startDate: string;
    plans:     drugPlanAddItem[];
}

// 用药计划添加返回值数组
interface drugPlanAddResItem {
    id:      number;
    drugId:  number;
    time:    string;
    content: string;
}

// 用药计划添加返回值
type drugPlanAddRes = ResponseType<{
    drugId:    number;
    startDate: string;
    endDate:   string;
    plans:     drugPlanAddResItem[];
}>

// 用药计划添加接口
export function drugPlanAddAPI(params: drugPlanAddParams): Promise<drugPlanAddRes> {
    return r.post(API.drugPlanAdd, params)
}

// 用药计划修改参数
interface drugPlanUpdateEndDateParams {
    id:      number;
    endDate: string;
}

// 用药计划添加返回值
type drugPlanUpdateEndDateRes = ResponseType<{
    id:             number;
    companyId:      number;
    elderlyId:      number;
    addTime:        string;
    familyName:     string;
    name:           string;
    counts:         number;
    unit:           string;
    expTime:        string;
    sum:            number;
    norms:          string;
    remarks:        string;
    addAccountId:   number;
    begId:          number;
    begName:        string;
    idCard:         string;
    addAccountName: string;
    elderlyName:    string;
    elderlyPhoto:   string;
    elderlyGender:  string;
    elderlyIdCard:  string;
    houseName:      string;
    buildingName:   string;
    startDate:      string;
    endDate:        string;
    plans:          string;
}>

// 用药计划修改接口
export function drugPlanUpdateEndDateAPI(params: drugPlanUpdateEndDateParams): Promise<drugPlanUpdateEndDateRes> {
    return r.put(API.drugPlanUpdateEndDate, params)
}

// 根据药品ID获取用药计划数值
interface drugPlanGetItem {
    id:      number;
    drugId:  number;
    time:    string;
    content: string;
}

// 根据药品ID获取用药计划返回值
type drugPlanGetRes = ResponseType<{
    drugId:    number;
    startDate: string;
    endDate:   string;
    plans:     drugPlanGetItem[];
}>


// 根据药品ID获取用药计划接口
export function drugPlanGetAPI(id: number): Promise<drugPlanGetRes> {
    return r.get(API.drugPlanGet + '/' + id)
}